package com.test.resumeanalysis.viewModel

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData


import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.setruth.doublewillow.utils.SPUtil
import com.setruth.mvvmbaseproject.network.ApiResponse
import com.setruth.mvvmbaseproject.network.RequestBuilder
import com.test.resumeanalysis.data.model.JobInfo
import com.test.resumeanalysis.data.model.JobPost
import com.test.resumeanalysis.data.model.resume.ResumeParse

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import retrofit2.Call
import retrofit2.Response
class PublicViewModel(application: Application) : AndroidViewModel(application) {

    val requestBuilder = RequestBuilder(application.applicationContext)
    val spUtil = SPUtil(application.applicationContext)
    fun <T> request(APIType: Class<T>): T = requestBuilder.getAPI(APIType)
    fun <T> Call<T>.getResponse(process: suspend (flow: Flow<ApiResponse<T>>) -> Unit) {
        viewModelScope.launch(Dispatchers.IO) {
            requestBuilder.apply {
                process(requestBuilder.getResponse {
                    this@getResponse.execute()
                })
            }
        }
    }


    private val _selectedPost  =  MutableLiveData<JobInfo>()
    val selectedPost: LiveData<JobInfo> = _selectedPost
    fun selectPost(jobInfo: JobInfo){
        _selectedPost.value = jobInfo
    }


    private val _selectedResume  =  MutableLiveData<Int>()
    val selectedResumeLiveData: LiveData<Int> = _selectedResume
    fun selectResume(position: Int){
        _selectedResume.value = position
    }

}